<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
	<base href="${pageContext.request.contextPath}/">
	<title>Title</title>
	<link rel="stylesheet" href="assets/layui/css/layui.css">
	<link rel="stylesheet" href="assets/css/base.css">
	<style>

	</style>
</head>
<body>
<div class="page">
	<form class="layui-form  fx-col" id="form" lay-filter="form_filter">

		<input type="hidden" name="teacher.id" value="${teacher.id}"/>
		<div class="layui-form-item">
			<label class="layui-form-label">教师姓名</label>
			<div class="layui-input-block">
				<input type="text" name="teacher.name" id="name" required  lay-verify="required" placeholder="请输入名称"
					   autocomplete="off" class="layui-input" value="${teacher.name}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">教师手机号</label>
			<div class="layui-input-block">
				<input type="text" name="teacher.phone" id="phone" required  lay-verify="required|phone" placeholder="请输入手机号"
					   autocomplete="off" class="layui-input" value="${teacher.phone}">
			</div>
		</div>
		<c:if test="${teacher == null}">
		<div class="layui-form-item">
			<label class="layui-form-label">登录密码</label>
			<div class="layui-input-block">
				<input type="text" name="teacher.password" id="pwd" required  lay-verify="required" placeholder="请输入密码"
					   autocomplete="off" class="layui-input" value="${teacher.password}">
			</div>
		</div>
		</c:if>
		<button  lay-submit="" class="layui-btn mt-15" id="save_btn" type="button">保存</button>
	</form>
</div>


</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="assets/layui/layui.all.js"></script>

<script>
	$(function () {
		var form = layui.form;



		//监听提交
		form.on('submit()', function(data){
			$.ajax({
				url: "teacher/save",
				type: "post",
				data: $("#form").serialize(),
				dataType: "json",
				success(res) {
					if (res.success) {
						layer.msg('保存成功', {icon: 6}, function () {
							window.parent.search();
						});

					} else {
						layer.msg(res.msg, {icon: 2});
					}
				}

			})
			return false;
		});



	})
</script>
</html>
